package com.spkj.srb.common.exception;

import com.spkj.srb.common.result.R;
import com.spkj.srb.common.result.ResponseEnum;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author spkj
 * @create 2022-06-12 21:27
 */
//@Component
//@RestControllerAdvice
public class UnifiedExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    public R handleException(){
        return R.error();
    }

    @ExceptionHandler(value = BadSqlGrammarException.class)
    public R handleBadSqlGrammarException(){
        return R.error().message(ResponseEnum.BAD_SQL_GRAMMAR_ERROR.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public R handleBusinessException(BusinessException e){
        return R.error().message(e.getMessage()).code(e.getCode());
    }
}
